home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / Lex.cpt / Lex / STDIO_LEXLIB.π folder / MAPCH.C < prev    next >
Text File  |  1990-06-03  |  2KB  |  78 lines

  1. /*
  2.   HEADER: CUG    nnn.nn;
  3.   TITLE:    LEX - A Lexical Analyser Generator
  4.   VERSION:       1.0 for IBM-PC
  5.   DATE:    Jan 30, 1985
  6.   DESCRIPTION:   A Lexical Analyser Generator. From UNIX
  7.   KEYWORDS:      Lexical Analyser Generator YACC C PREP
  8.   SYSTEM:    IBM-PC and Compatiables
  9.   FILENAME:      MAPCH.C
  10.   WARNINGS:      This program is not for the casual user. It will
  11.     be useful primarily to expert developers.
  12.   CRC:    N/A
  13.   SEE-ALSO:      YACC and PREP
  14.   AUTHORS:       Scott Guthery 11100 leafwood lane Austin, TX 78750
  15.   COMPILERS:     DESMET-C
  16.   REFERENCES:    UNIX Systems Manuals
  17. */
  18. /*
  19.  * Bob Denny     28-Aug-82 Move stdio dependencies to lexerr(), lexget(),
  20.  *    lexech() and mapch(). This is one of 4 modules in
  21.  *    lexlib which depend upon the standard I/O package.
  22.  * Scott Guthery 20-Nov-83 Adapt for IBM PC & DeSmet C
  23.  */
  24.  
  25. /*
  26.  * mapch -- handle escapes within strings
  27.  */
  28. #define    STDIO_LEXLIB
  29.  
  30. #include <stdio.h>
  31. #include "lex.h"
  32.  
  33. extern SHORTINT yyline;
  34.  
  35. mapch(delim, esc)
  36. int delim;
  37. int esc;
  38. {
  39.     register SHORTINT c, octv, n;
  40.  
  41.     if ((c = lexchar())==delim)
  42.         return(EOF);
  43.     if (c==EOF || c=='\n') {
  44.         lexerror("Unterminated string");
  45.         ungetc(c, lexin);
  46.         return(EOF);
  47.         }
  48.     if (c!=esc)
  49.         return(c);
  50.     switch (c=lexchar()) {
  51.         case 't':
  52.             return('\t');
  53.         case 'n':
  54.             return('\n');
  55.         case 'f':
  56.             return('\f');
  57.         case '\"': case '\'':
  58.             return(c);
  59.         case 'e':
  60.             return('\e');
  61.         case 'p':
  62.             return(033);
  63.         case 'r':
  64.             return('\r');
  65.         case '0': case '1': case '2': case '3':
  66.         case '4': case '5': case '6': case '7':
  67.             octv = c-'0';
  68.             for (n = 1; (c = lexchar())>='0' && c<='7' && n<=3; n++)
  69.             octv = octv*010 + (c-'0');
  70.             ungetc(c, lexin);
  71.             return(octv);
  72.         case '\n':
  73.             yyline++;
  74.             return(mapch(delim, esc));
  75.         }
  76.     return(c);
  77. }
  78.